package com.example.yinhangmiaosha.filter;

import com.example.yinhangmiaosha.service.TimeService;
import org.apache.shiro.web.filter.AccessControlFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class TimeFilter extends AccessControlFilter {
    private static final Logger LOGGER = LoggerFactory.getLogger(TimeFilter.class);

    @Autowired
    private TimeService timeService;

    @Override
    protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object o) throws Exception {
        System.out.println("TimeFilter");
        return timeService.getTimeIsPermitted();
    }

    @Override
    protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
        LOGGER.error("拒绝请求，不在活动时间范围！");
        return false;
    }


}
